package com.relytosoft.mizar.media.display.services.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.relytosoft.dubhe.common.core.exception.ServiceException;
import com.relytosoft.dubhe.common.core.object.ResponseResult;
import com.relytosoft.mizar.media.camera.api.entity.CameraPlatform;

import java.util.Optional;

/**
 * 结果返回处理工具
 *
 * @author hj
 * @version 1.0
 * @date 2022/4/14 18:24
 * @ClassName ResponseUtils
 */
public class ResponseUtils {


    public static String getCameraIndex(ResponseResult<CameraPlatform> result){
        //判断
       return Optional.ofNullable(result)
                .map(r -> result.getData())
                .map(d -> d.getPlatformChannelCode())
                .orElseThrow(() ->  new ServiceException("设备信息未找到！"));
    }
    public static String getStreamProxyKey(String result){
        JSONObject jsonObject= JSON.parseObject(result);
        return  jsonObject.getString("key");
    }
}
